package com.boxuegu.view;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ListView;

import com.boxuegu.R;
import com.boxuegu.adapter.ExercisesAdapter;
import com.boxuegu.bean.ExercisesBean;

import java.util.ArrayList;
import java.util.List;

public class ExercisesView {
    private View view;
    private ListView lv_list;
    private int bid[]={R.drawable.exercises_bg_1, R.drawable.exercises_bg_2, R.drawable.exercises_bg_3, R.drawable.exercises_bg_4};

    public ExercisesView(Activity context){
        LayoutInflater layoutInflater=LayoutInflater.from(context);
        view=layoutInflater.inflate(R.layout.main_view_exercises,null);
        //为listview中填充数据。1、生成数据源；2、生成数据适配器对象；3、为listview设置数据适配器
        lv_list=view.findViewById(R.id.lv_list);

        List<ExercisesBean> beans=new ArrayList<ExercisesBean>();
        for(int i=0;i<15;i++){
            ExercisesBean bean=new ExercisesBean();
            bean.setId(i+1);
            bean.setTitle("第"+(i+1)+"章");
            bean.setContent("共计5题");
            bean.setBackgroundId(bid[i%4]);
            beans.add(bean);
        }

        ExercisesAdapter exercisesAdapter=new ExercisesAdapter(beans,context);
        lv_list.setAdapter(exercisesAdapter);




    }

    public View getView() {
        return view;
    }
}
